// This File is part of the "GmailNotifier2" Project
// 
// Copyright  2009 sometmes@gmail.com
// All rights reserved
// 
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;

namespace Notify2
{
    public partial class ExceptionMessageBox : Form
    {
        public ExceptionMessageBox()
        {
            InitializeComponent();
        }

        public static void Show(string title, string msg)
        {
            ExceptionMessageBox dlg = new ExceptionMessageBox();
            dlg.messageTextBox.Text = msg;
            dlg.Text = title;
            dlg.ShowDialog();
        }

        public static void Show(string title, Exception ex)
        {
            Exception baseEx = ex.GetBaseException();
            DateTime modified = File.GetLastWriteTime(Application.ExecutablePath);
            string preamble = Path.GetFileName(Application.ExecutablePath) + "  v" + Application.ProductVersion + " - " + modified.ToShortDateString() + " " + modified.ToLongTimeString();

            string description = baseEx.Message;
            string type = baseEx.GetType().FullName;
            string data = "";
            foreach (DictionaryEntry de in baseEx.Data)
                data += "\r\n" + de.Key + ": " + de.Value;
            string stack = baseEx.StackTrace;

            ExceptionMessageBox.Show(title, preamble + "\r\n\r\n" + description + " (" + type + ")" + data + "\r\n\r\nStack Trace:\r\n" + stack);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Clipboard.SetText("Title: " + this.Text + "\r\n" + messageTextBox.Text);
            messageTextBox.SelectAll();
            messageTextBox.Focus();
        }
    }
}
